package cn.elwy.rcp.ui.provider;

import java.util.List;

import org.eclipse.jface.viewers.IContentProvider;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ViewerSorter;

/**
 * 数据提供类
 * 
 * @author huangsq
 * @version 1.0, 2014-06-23
 * @since 1.0, 2014-06-23
 */
public class DataProvider {

  private DataParser parser;
  private HeaderConfig configure;

  private ViewerSorter sorter;
  private IContentProvider contentProvider;
  private ILabelProvider labelProvider;
  private DataCheckStateProvider checkStateProvider;

  private List<?> input;

  public IContentProvider getContentProvider() {
    return contentProvider;
  }

  public ILabelProvider getLabelProvider() {
    return labelProvider;
  }

  public DataCheckStateProvider getCheckStateProvider() {
    return checkStateProvider;
  }

  public List<?> getInput() {
    return input;
  }

  public void setContentProvider(IContentProvider contentProvider) {
    this.contentProvider = contentProvider;
    if (((DataContentProvider) contentProvider).getParser() == null && parser != null) {
      ((DataContentProvider) contentProvider).setParser(parser);
    }
  }

  public void setLabelProvider(ILabelProvider labelProvider) {
    this.labelProvider = labelProvider;
    if (((DataLabelProvider) labelProvider).getParser() == null && parser != null) {
      ((DataLabelProvider) labelProvider).setParser(parser);
    }
  }

  public void setCheckStateProvider(DataCheckStateProvider checkStateProvider) {
    this.checkStateProvider = checkStateProvider;
    if (checkStateProvider.getParser() == null && parser != null) {
      checkStateProvider.setParser(parser);
    }
  }

  public ViewerSorter getSorter() {
    return sorter;
  }

  public void setSorter(ViewerSorter sorter) {
    this.sorter = sorter;
  }

  public void setInput(List<?> input) {
    this.input = input;
  }

  public DataParser getParser() {
    return parser;
  }

  public void setParser(DataParser parser) {
    this.parser = parser;
    if (contentProvider != null) {
      ((DataContentProvider) contentProvider).setParser(parser);
    }
    if (labelProvider != null) {
      ((DataLabelProvider) labelProvider).setParser(parser);
    }
    if (checkStateProvider != null) {
      checkStateProvider.setParser(parser);
    }
  }

  public HeaderConfig getConfigure() {
    return configure;
  }

  public void setConfigure(HeaderConfig configure) {
    this.configure = configure;
  }
}
